/*
 * @Description:
 * @Autor: lcz
 * @Date: 2022-06-15 12:43:47
 * @LastEditors: lcz
 * @LastEditTime: 2022-06-15 12:56:22
 */
const CracoAntDesignPlugin = require('craco-antd')
const CracoAlias = require('craco-alias')
const CracoLessPlugin = require('craco-less')
const path = require('path')

module.exports = {
  plugins: [
    {
      plugin: CracoAntDesignPlugin,
      options: {
        customizeTheme: {
          '@primary-color': '#1DA57A',
        },
      },
    },
    {
      plugin: CracoLessPlugin,
      options: {
        cssLoaderOptions: {
          modules: { localIdentName: '[local]_[hash:base64:5]' },
        },
        modifyLessRule: function (lessRule, _context) {
          lessRule.test = /\.(module)\.(less)$/
          lessRule.exclude = path.join(__dirname, 'node_modules')
          return lessRule
        },
      },
    },
    /* 别名设置 */
    {
      plugin: CracoAlias,
      options: {
        source: 'tsconfig',
        baseUrl: './src',
        tsConfigPath: './tsconfig.extend.json',
      },
    },
  ],
  devServer: devServerConfig => {
    return {
      ...devServerConfig,
      // 服务开启gzip
      compress: true,
      proxy: {
        '/api': {
          target: 'https://baidu.com/',
          changeOrigin: true,
          xfwd: false,
        },
      },
    }
  },
  webpack: {
    // 配置别名,可以直接从根目录下面开始查找文件
    alias: {
      '@': path.resolve(__dirname, 'src'),
      components: path.resolve(__dirname, 'src/components'),
    },
  },
}
